home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Amos / AlienBreed3 / ALIEN_BREED_III.AMOS / ALIEN_BREED_III.amosSourceCode next >
Encoding:
AMOS Source Code  |  1996-02-23  |  17.5 KB  |  509 lines

  1. ' This tutorial is from Mr. AMOS Club issue 5, 
  2. ' edited by Brian Bell and others, which folded
  3. ' in 1994 with issue 6.  No other AMOS group before
  4. ' or after has matched its code tutorials.   
  5. '
  6. '***************************************************************************** 
  7. '
  8. '  
  9. '                     WELCOME TO THE ALIEN BREED CLONE 
  10. '                    ----------------------------------
  11. '
  12. ' Over the next few issues I will be showing YOU how to write a game.  Brian 
  13. ' and myself decided that I should show you how to write an Alien Bredd clone, 
  14. ' so here goes...
  15. '
  16. ' I know that it doesn't look much like Alien Breed at the minute, but have
  17. ' patience, once I get some new graphics and a bit of time to work on this 
  18. ' project, you will see a HUGE improvement.  Promise.
  19. '
  20. ' Okay, the first thing I do when I'm writing a game, is to sit and think  
  21. ' about it for a while, it helps a lot if you are able to identify what
  22. ' the game has to achieve.  To do this I am going to come up with a list of
  23. ' things that I would like to put in the game, then as the months go by, 
  24. ' I can convert these ideas into code.  So the following is a list of ideas
  25. ' that I have at this early stage, as I attempt each one, I will put my  
  26. ' thoughts about them, and whether they worked as I expected them to.
  27. '
  28. '                                IDEAS 
  29. '                               -------
  30. '
  31. ' NUMBER 1 - A MULTI-DIRECTIONAL JOYSTICK CONTROL ROUTINE. 
  32. '
  33. ' The first thing that I like to write, when producing a game, is the joystick 
  34. ' control routine.  That way I can start to get a feel for the game, and have
  35. ' some feedback about how it's going to work.
  36. '
  37. ' As you can see, I have decided that I want the Joystick routine to be  
  38. ' slightly different.  Most AMOS games let your player face in four directions 
  39. ' Up, down, left and right, but I want to cater for the four diaganol  
  40. ' directions as well.  This results in a bit more work, but the game will
  41. ' look a lot better for it.
  42. '
  43. ' This routine has been implemented, and it works just like I wanted it to,
  44. ' it has been fully commented so that you can learn from it. 
  45. '  
  46. '
  47. ' NUMBER 2 - INTELLIGENT COMPUTER-CONTROLLED OPPONENTS.
  48. '
  49. ' This is a bit of a challenge.  In one of my previous game's, "Kendo's Super    
  50. ' Pong"(KSP), a tennis game, I wanted to have a one-player option.  I had to 
  51. ' think of a way to make the computer control the bat, and try to hit the ball,  
  52. ' but obviously he had to be able to be beaten.  I thought this would be 
  53. ' really hard to do, but once I sat down and thought about it, I came up with  
  54. ' the solution really quickly. 
  55. '
  56. ' Remember that all Bobs are displayed on a coordinate system, and so if 
  57. ' we want to make a Bob chase another Bob, all we have to do is fiddle about 
  58. ' with his coordinates until they match.  There were other things that had 
  59. ' to be done in KSP to change the computers reaction time, and things like 
  60. ' that, because there were three difficulty levels, but I will be explaining 
  61. ' those fully in the KENDO KOLLECTION. 
  62. '
  63. ' Anyway, the way that I make the computer-controlled tank home in on the  
  64. ' player is to say something like... 
  65. '
  66. ' If COMPUTER_TANK_X < PLAYER_TANK_X 
  67. '    Add COMPUTER_TANK_X,SPEED 
  68. ' End If 
  69. '
  70. ' This would change the X coordinate of the computers tank, until it matched 
  71. ' the players X position.
  72. '
  73. ' I hope this makes artificial intelligence a bit easier to understand.
  74. ' If you have any more ideas about artificial intelligence, or programs
  75. ' dealing with it then send them in.  I'd like to see what other people  
  76. ' have done in this area.  
  77. '
  78. ' If you are still a bit unsure about Artificial Intelligence, then you can
  79. ' write to me at the AMOS AGONIES address, in the Club Section.  Try and 
  80. ' understand how it works so far, because next month I will be making the  
  81. ' computers tank collide with the scenery, and this will mean that the 
  82. ' intelligence routine will be even more complicated.
  83. '
  84. '
  85. ' NUMBER 3 - A MAPPING SYSTEM. 
  86. '
  87. ' This will be in next issue's version.  In this version, the background is  
  88. ' simply a Packed Picture, but this takes up too much memory, and it isn't 
  89. ' really possible to make the tanks collide with the walls.  Next issue the
  90. ' mapping systen will DEFINITELY be here. I didn't put it in this version  
  91. ' because I don't want to go too fast.  The mapping system will be fairly
  92. ' easy to understand anyway, so even if you have never used mapping before 
  93. ' by the time you have read next months issue YOU should be an EXPERT.   
  94. ' Oh yeah, I'll be using the brand new EFFECT blocks that Brian has built
  95. ' into MEGA-MAC-MAP, so you can see how to use this EXCELLENT new feature. 
  96. '
  97. '
  98. ' NUMBER 4 - A LARGE SCROLLING BACKGROUND. 
  99. '
  100. ' I'd like to make the playing area a big scrolling background, rather than  
  101. ' have a single-screen flick-screen format.  I have been told by loads of
  102. ' people that this just isn't possible in AMOS, but we'll see... 
  103. '
  104. '
  105. ' NUMBER 5 - LOADS OF BADDIES
  106. '
  107. ' This will come in at a later stage, when I will hopefully have some  
  108. ' new graphics.  I want to have different sorts of aliens running around,
  109. ' as well as other tanks, and, ooh, loads of different stuff...
  110. ' Just wait and see. 
  111. '
  112. ' I will also have a regenerating system for the aliens, where when you  
  113. ' shoot one alien, another one is generated somewhere else, this will give 
  114. ' the appearance of having loads of aliens running around, when we might only  
  115. ' have five or six.
  116. '
  117. '
  118. ' NUMBER 6 - A TWO-PLAYER OPTION 
  119. '
  120. ' I haven't given this much consideration yet, but it would be easy enough 
  121. ' to have a "versus" mode, where the two tanks are placed on the one screen, 
  122. ' and have to battle each other.  It would be good to have two players 
  123. ' fighting the aliens simultaneously, as in the real Alien Breed, but I'm not
  124. ' sure if AMOS could handle that, without slowing down a lot.  It MIGHT work 
  125. ' if I reduce the number of Aliens on screen.  I think it would be cool to 
  126. ' have to fight the other player for credits and stuff.
  127. '
  128. '
  129. ' NUMBER 7 - BONUSES 
  130. '
  131. ' I'll have to come up with a way of scattering bonuses around the game-area,
  132. ' this shouldn't be too difficult, it will probably be done in a similar way 
  133. ' to Brians Dizzy clone. 
  134. '
  135. '
  136. ' Thats all I can think of for the minute, but it's probaly enough to be 
  137. ' going on with ( Understatement ! ).  If you have any ideas then you can send 
  138. ' them in to me at the following address, and I'll try to accomadate them
  139. ' in a future version. 
  140. '
  141. ' Neil Kennedy 
  142. ' 66 Belmont Church Road 
  143. ' Belfast BT4 3FG
  144. ' Northern Ireland.
  145. '
  146. ' And don't forget that you can also send your AMOS AGONIES to this address. 
  147. '
  148. '***************************************************************************** 
  149.  
  150. ' ***** Set up the main game screen, and turn off the default settings.
  151. Screen Open 0,320,256,16,Lowres
  152. Flash Off : Curs Off : Cls 0 : Hide 
  153.  
  154. ' ***** Load in the graphics, if needed. 
  155. If Length(1)=False
  156.    Load "Tanked_Up_Big_Bobs.Abk"
  157. End If 
  158.  
  159. ' ***** Load in the background screen, if needed.  
  160. If Length(10)=False
  161.    Load "Tanked_Up_Background_Pic.Abk"
  162. End If 
  163.  
  164. MAKE_BACKGROUND_SCREEN
  165.  
  166. ' ***** Switch on Double Buffering, so that there is no flickering.
  167. Double Buffer 
  168.  
  169.  
  170. '***************************************************************************** 
  171. '
  172. ' Here, I am declaring some variables as Global variables.  This means that
  173. ' they can be used inside all my procedures, without me having to declare
  174. ' them as "Shared" inside the individual procedures.  Usually I would just 
  175. ' use Shared, but this program is going to be quite big when it's finished,
  176. ' so its moresensible to declare the variables Globally, so I don't have to
  177. ' worry about them anymore 
  178. '
  179. '***************************************************************************** 
  180.  
  181. Global _TANK_1_XPOS,_TANK_1_YPOS,_TANK_1_IMAGE,_TANK_1_SPEED
  182. Global _TANK_2_XPOS,_TANK_2_YPOS,_TANK_2_IMAGE,_TANK_2_SPEED
  183.  
  184. ' ***** Set up the defaults for Tank 1.
  185. _TANK_1_XPOS=300 : _TANK_1_YPOS=200 : _TANK_1_IMAGE=1 : _TANK_1_SPEED=2
  186. Bob 1,_TANK_1_XPOS,_TANK_1_YPOS,_TANK_1_IMAGE
  187.  
  188. ' ***** Set up the defaults for Tank 2.
  189. _TANK_2_XPOS=50 : _TANK_2_YPOS=50 : _TANK_2_IMAGE=11 : _TANK_2_SPEED=1
  190. Bob 2,_TANK_2_XPOS,_TANK_2_YPOS,_TANK_2_IMAGE
  191.  
  192.  
  193. ' ***** Now I start the main game loop.
  194. Repeat 
  195.    
  196.    ' ***** Checks for pressing the joystick up, and then checks for the 
  197.    ' ***** diagonal directions.  It may look complicated at first, but I  
  198.    ' ***** have had to write it this way to get the game running at a good  
  199.    ' ***** speed. 
  200.    If Jup(1)
  201.       
  202.       ' ***** Change the Y-position.  Because of the way I have structered 
  203.       ' ***** this routine, we only have to change the Y Axis once 
  204.       ' ***** whereas it would usually have to be done three times, i.e. 
  205.       ' ***** whenever the joystick is pressed up, up-right and up-left. 
  206.       Add _TANK_1_YPOS,-_TANK_1_SPEED
  207.       
  208.       ' ***** This bit checks if the player is pushing the joystick up-right.
  209.       If Jright(1)
  210.          
  211.          ' ***** This changes the X position, so that the tank goes up-right. 
  212.          ' ***** Then we assign it the correct image  
  213.          Add _TANK_1_XPOS,_TANK_1_SPEED
  214.          _TANK_1_IMAGE=6
  215.          
  216.          ' ***** This says, "If the user hasn't pressed the joystick up-right,  
  217.          ' ***** then has he pressed it up-left instead ? ", if so then the 
  218.          ' ***** next bit of code is executed.          
  219.          
  220.       Else 
  221.          
  222.          
  223.          If Jleft(1)
  224.             
  225.             Add _TANK_1_XPOS,-_TANK_1_SPEED
  226.             _TANK_1_IMAGE=5
  227.             
  228.          Else 
  229.             
  230.             ' ***** If the user hasn't pressed up-right or up-left on the
  231.             ' ***** the joystick, then we know that he MUST have pressed up on 
  232.             ' ***** its own, so all we have to do is give the tank the right image.
  233.             ' ***** remember that we have already changed the Y coordinate so that the 
  234.             ' ***** tank has moved up the screen, and the tank isn't moving to the 
  235.             ' ***** side so we don't need to change the X coordinate.          
  236.             
  237.             _TANK_1_IMAGE=1
  238.             
  239.          End If 
  240.          
  241.       End If 
  242.       
  243.    End If 
  244.    
  245.    
  246.    ' ***** This is the checks for pressing the joystick down, it is much the
  247.    ' ***** same as the code for moving the tank upwards.  It looks after  
  248.    ' ***** the joystick being pressed down, down-right and down-left.     
  249.    If Jdown(1)
  250.       
  251.       ' ***** This changes the Y coordinate, so that the tank is moved down
  252.       ' ***** the screen.
  253.       Add _TANK_1_YPOS,_TANK_1_SPEED
  254.       
  255.       ' ***** This checks for the joystick being pressed down-right. 
  256.       If Jright(1)
  257.          
  258.          ' ***** Add the speed to the tanks X position, and assign the tank 
  259.          ' ***** the image of it facing down-right. 
  260.          Add _TANK_1_XPOS,_TANK_1_SPEED
  261.          _TANK_1_IMAGE=7
  262.          
  263.          ' ***** This says, "If the user hasn't pressed the joystick  
  264.          ' ***** down-right, then has he pressed it down-left instead ? ",  
  265.          ' ***** if so then the next bit of code is executed.         
  266.          
  267.       Else 
  268.          
  269.          
  270.          
  271.          If Jleft(1)
  272.             
  273.             Add _TANK_1_XPOS,-_TANK_1_SPEED
  274.             _TANK_1_IMAGE=8
  275.             
  276.          Else 
  277.             
  278.             ' ***** If the user hasn't pressed down-right or down-left on the
  279.             ' ***** the joystick, then we know that he MUST have pressed down on 
  280.             ' ***** its own, so all we have to do is give the tank the right image.
  281.             ' ***** remember that we have already changed the Y coordinate so that the 
  282.             ' ***** tank has moved donw the screen, and the tank isn't moving to the 
  283.             ' ***** side so we don't need to change the X coordinate.          
  284.             
  285.             _TANK_1_IMAGE=3
  286.             
  287.          End If 
  288.          
  289.       End If 
  290.       
  291.    End If 
  292.    
  293.    
  294.    
  295.    '**************************************************************************
  296.    '
  297.    ' Now that we have taken care of moving the tank up, up-right, up-left,
  298.    ' down, down-right and down-left, we have to take care of the two  
  299.    ' directions that we haven't dealt with so far.  Left and Right. 
  300.    '
  301.    ' You may be wondering why I have said below...  
  302.    '
  303.    ' If Jright(1) and Jup(1)=false and Jdown(1)=False.    
  304.    '
  305.    ' and not
  306.    '  
  307.    ' If Jright(1) 
  308.    '
  309.    ' Well, this is so that the tank doesn't get moved twice in the same 
  310.    ' direction in the same loop.  If we pressed up-right on the joystick, 
  311.    ' then the tank would be moved up and to the right.  But when the program  
  312.    ' came down to this part, up-right would also be translated as right on its
  313.    ' own, so the tank would be moved twice to the right, and it would have
  314.    ' the wrong image. 
  315.    '  
  316.    ' I could have used the "Joy(1)" function, and then checked to see what
  317.    ' number it returned, but this won't do when I have to put in a firing 
  318.    ' routine. 
  319.    '
  320.    '              TRUST ME I KNOW WHAT I'M DOING. ( I hope )  
  321.    '
  322.    ' Uncomment the next line, and comment the line after it if you want 
  323.    ' to see what I mean.
  324.    '
  325.    '**************************************************************************
  326.    
  327.    '  If Jright(1)
  328.    If Jright(1) and Jup(1)=False and Jdown(1)=False
  329.       Add _TANK_1_XPOS,_TANK_1_SPEED
  330.       _TANK_1_IMAGE=2
  331.    End If 
  332.    
  333.    If Jleft(1) and Jup(1)=False and Jdown(1)=False
  334.       Add _TANK_1_XPOS,-_TANK_1_SPEED
  335.       _TANK_1_IMAGE=4
  336.    End If 
  337.    
  338.    ' ***** This calls the procedure that controls the computers tank. 
  339.    CONTROL_COMPUTER_TANK
  340.    
  341.    ' ***** This calls the procdure that checks if the tank has gone off the 
  342.    ' ***** edges of the screen. 
  343.    CHECK_SCREEN_LIMITS
  344.    
  345.    ' ***** Place the bobs on the screen.    
  346.    
  347.    ' ***** This is the players tank.  It is Bob number 1. 
  348.    Bob 1,_TANK_1_XPOS,_TANK_1_YPOS,_TANK_1_IMAGE
  349.    
  350.    ' ***** This is the computers tank.  It is Bob number 2. 
  351.    Bob 2,_TANK_2_XPOS,_TANK_2_YPOS,_TANK_2_IMAGE
  352.    
  353.    
  354.    ' ***** Wait for the next Vertical Blank, which smooths everything out 
  355.    Wait Vbl 
  356.    
  357.    ' ***** We repeat this loop until a mouse key is pressed.    
  358. Until Mouse Click
  359.  
  360. ' ***** The program drops through to here when a mouse button is pressed,  
  361. ' ***** so I just have to close everything down. 
  362.  
  363. ' ***** Fade out the screen. 
  364. Fade 2
  365. Wait 30
  366.  
  367. ' ***** Thats it.  
  368. End 
  369.  
  370.  
  371. Procedure CONTROL_COMPUTER_TANK
  372.    
  373.    ' ***** This procedure takes care of moving the computer-controlled tank.
  374.    ' ***** It is basically the same as the code that moves the players
  375.    ' ***** tank, but we don't have any Joystick presses to go on, so we have
  376.    ' ***** to make the computer decide which way the tank is going to go. 
  377.    
  378.    ' ***** Check for moving the tank up, up-right and up-left 
  379.    If _TANK_2_YPOS>_TANK_1_YPOS
  380.       
  381.       Add _TANK_2_YPOS,-_TANK_2_SPEED
  382.       
  383.       If _TANK_2_XPOS<_TANK_1_XPOS
  384.          
  385.          Add _TANK_2_XPOS,_TANK_2_SPEED
  386.          _TANK_2_IMAGE=16
  387.          
  388.       Else 
  389.          
  390.          
  391.          If _TANK_2_XPOS>_TANK_1_XPOS
  392.             
  393.             Add _TANK_2_XPOS,-_TANK_2_SPEED
  394.             _TANK_2_IMAGE=15
  395.             
  396.          Else 
  397.             
  398.             _TANK_2_IMAGE=11
  399.             
  400.          End If 
  401.          
  402.       End If 
  403.       
  404.    End If 
  405.    
  406.    
  407.    ' ***** Check for moving the tank down, down-right and down-left 
  408.    If _TANK_2_YPOS<_TANK_1_YPOS
  409.       
  410.       Add _TANK_2_YPOS,_TANK_2_SPEED
  411.       
  412.       If _TANK_2_XPOS<_TANK_1_XPOS
  413.          
  414.          Add _TANK_2_XPOS,_TANK_2_SPEED
  415.          _TANK_2_IMAGE=17
  416.          
  417.       Else 
  418.          
  419.          If _TANK_2_XPOS>_TANK_1_XPOS
  420.             
  421.             Add _TANK_2_XPOS,-_TANK_2_SPEED
  422.             _TANK_2_IMAGE=18
  423.             
  424.          Else 
  425.             
  426.             _TANK_2_IMAGE=13
  427.             
  428.          End If 
  429.          
  430.       End If 
  431.       
  432.    End If 
  433.    
  434.    
  435.    ' ***** Check for moving the tank to the right.  
  436.    If _TANK_2_XPOS<_TANK_1_XPOS and _TANK_2_YPOS=_TANK_1_YPOS
  437.       
  438.       Add _TANK_2_XPOS,_TANK_2_SPEED
  439.       _TANK_2_IMAGE=12
  440.       
  441.    End If 
  442.    
  443.    ' ***** Check for moving the tank to the left. 
  444.    If _TANK_2_XPOS>_TANK_1_XPOS and _TANK_2_YPOS=_TANK_1_YPOS
  445.       
  446.       Add _TANK_2_XPOS,-_TANK_2_SPEED
  447.       _TANK_2_IMAGE=14
  448.       
  449.    End If 
  450.    
  451.    ' ***** Phew, that didn't hurt too much did it ?  When you run the program 
  452.    ' ***** I think that the computer tank looks pretty cool, when you consider
  453.    ' ***** the small amount of code that I had to write to get him moving.    
  454.    
  455. End Proc
  456.  
  457. Procedure MAKE_BACKGROUND_SCREEN
  458.    
  459.    ' ***** As I said at the start of the program, I am using a Packed Picture 
  460.    ' ***** for the the background this month, which means that the tanks can
  461.    ' ***** drive over the walls, when they should really stop.  Next issue
  462.    ' ***** will see the introduction of the mapping system. 
  463.    
  464.    ' ***** Hide the screen from view.   
  465.    Screen Hide 0
  466.    
  467.    ' ***** Unpack the background screen onto screen 0.
  468.    Unpack 10 To 0
  469.    
  470.    ' ***** Turn all the colours to black. 
  471.    For LOP=1 To 15
  472.       Colour LOP,$0
  473.    Next LOP
  474.    
  475.    ' ***** Bring screen 0 into view again, but we can't see anything
  476.    ' ***** because all the colours have been turned to black.     
  477.    Screen Show 0
  478.    
  479.    ' ***** Now fade the screen in, using the colours from the Sprite bank 
  480.    Fade 2 To -1
  481.    Wait 10
  482.    
  483. End Proc
  484.  
  485. Procedure CHECK_SCREEN_LIMITS
  486.    
  487.    ' ***** This is just to make sure that the players tank cant go off the
  488.    ' ***** sides of the screen.  I don't have to worry about the computer-
  489.    ' ***** controlled tank, because he can't go anywhere that the player
  490.    ' can't go.  Sneaky huh ?
  491.    
  492.    If _TANK_1_XPOS>300
  493.       _TANK_1_XPOS=300
  494.    End If 
  495.    
  496.    If _TANK_1_XPOS<15
  497.       _TANK_1_XPOS=15
  498.    End If 
  499.    
  500.    If _TANK_1_YPOS<20
  501.       _TANK_1_YPOS=20
  502.    End If 
  503.    
  504.    If _TANK_1_YPOS>220
  505.       _TANK_1_YPOS=220
  506.    End If 
  507.    
  508.    
  509. End Proc